load("@bazel_skylib//rules:copy_file.bzl", "copy_file")
load("@rules_cc//cc:cc_binary.bzl", "cc_binary")
load("@rules_cc//cc:cc_library.bzl", "cc_library")

licenses(["notice"])

exports_files(["LICENSE"])

INCLUDES = [
    ".",
    "include",
    "x86",
    "asm",
    "disasm",
    "output",
]

COPTS = select({
    "@platforms//os:windows": [],
    "//conditions:default": [
        "-w",
        "-DHAVE_CONFIG_H",
    ],
})

copy_file(
    name = "config_src",
    src = select({
        "@platforms//os:macos": "config_macos.h",
        "//conditions:default": "config_linux.h",
    }),
    out = "config/config.h",
)

cc_library(
    name = "nasm_2_16_03",
    srcs = glob(
        include = [
            "asm/*.c",
            "common/*.c",
            "disasm/*.c",
            "macros/*.c",
            "nasmlib/*.c",
            "output/*.c",
            "stdlib/*.c",
            "x86/*.c",
        ],
        exclude = [
            "asm/nasm.c",
        ],
    ),
    hdrs = [":config_src"] + glob([
        "*.h",
        "asm/*.h",
        "autoconf/*.h",
        "config/*.h",
        "disasm/*.h",
        "include/*.h",
        "nasmlib/*.h",
        "output/*.h",
        "x86/*.h",
    ]),
    copts = COPTS,
    includes = INCLUDES,
)

cc_binary(
    name = "nasm",
    srcs = [
        "asm/nasm.c",
    ],
    copts = COPTS,
    includes = INCLUDES,
    visibility = ["//visibility:public"],
    deps = [
        ":nasm_2_16_03",
    ],
)
